//! \file Element.cpp
//! \brief TODO: Document
// -----------------------------------------------------------------------------
//! This program is free software; you can redistribute it and/or
//! modify it under the terms of the GNU General Public License
//! as published by the Free Software Foundation; either version 2
//! of the License, or (at your option) any later version.
//!
//! This program is distributed in the hope that it will be useful,
//! but WITHOUT ANY WARRANTY; without even the implied warranty of
//! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//! GNU General Public License for more details.
//!
//! You should have received a copy of the GNU General Public License
//! along with this program; if not, write to the Free Software Foundation,
//! Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
// -----------------------------------------------------------------------------

#include "Element.h"
#include "GuiCEGUI.h"

using namespace CEGUI;

// =====[ Local Definitions ]===================================================

// =====[ Local DataTypes ]=====================================================

// =====[ Local Variables ]=====================================================
Window *Element::m_pParent = NULL;

// =====[ Local Functions ]=====================================================

// =====[ Private (Internal) Methods ]==========================================

// =====[ Local Implementation ]================================================


// =============================================================================
// FxName
// -----------------------------------------------------------------------------
//! TODO: document
//!
//! \param [in] Arg
//!   TODO: document
//!
//! \retval Exception
//!   The success status of the requested operation.
//!   - eOKAY: Execution occurred as requested.
//!   .
//!
//! \b Example: \code
//! FxName(0);
//! \endcode
// -----------------------------------------------------------------------------
tERROR Element::create(CEGUI::Window *pParent)
{
  // Return success.
  return (ERR_NONE);
};


// =============================================================================
// FxName
// -----------------------------------------------------------------------------
//! TODO: document - Only allows a single instance to be created.
//!
//! \param [in] Arg
//!   TODO: document
//!
//! \retval Exception
//!   The success status of the requested operation.
//!   - eOKAY: Execution occurred as requested.
//!   .
//!
//! \b Example: \code
//! FxName(0);
//! \endcode
// -----------------------------------------------------------------------------
bool Element::createSingle(Window *pParent)
{
  // We can only create one instance.
  if (m_pParent != NULL)
    { return (false); }

  // Determine and save our parent.
  if (pParent != NULL)
    { m_pParent = pParent; }
  else
    { m_pParent = GuiCEGUI::getRoot(); }

  // Return success.
  return (true);
}


// =============================================================================
// FxName
// -----------------------------------------------------------------------------
//! TODO: document
//!
//! \param [in] Arg
//!   TODO: document
//!
//! \retval Exception
//!   The success status of the requested operation.
//!   - eOKAY: Execution occurred as requested.
//!   .
//!
//! \b Example: \code
//! FxName(0);
//! \endcode
// -----------------------------------------------------------------------------
void Element::subscribeEvent(const String& Widget, const String& Event, const Event::Subscriber& Method)
{
  // Get the window manager to work with.
  WindowManager* pWm = GuiCEGUI::getWm();

  // If the requested widget exists, subscribe the event to it.
  if (pWm->isWindowPresent(Widget))
  {
    Window *pWindow = pWm->getWindow(Widget); // Get the widget.
    pWindow->subscribeEvent(Event, Method);   // Subscribe the event.
  }
}
